{% extends "./inc/base.html" %} {% block style %}
<!--<link rel="stylesheet" href="/static/admin/js/zTree/metroStyle/metroStyle.css" type="text/css">-->
<link rel="stylesheet" href="/static/admin/js/zTree/zTreeStyle/zTreeStyle.css" type="text/css">
<style>
    .table > thead > tr > th, .table > tbody > tr > th, .table > tfoot > tr > th, .table > thead > tr > td, .table > tbody > tr > td, .table > tfoot > tr > td{
        vertical-align:middle;
    }
</style>
 {% endblock%} {% block content %}
<section class="vbox">
    <section id="bjax-target">
        <section class="hbox stretch">
            <!-- side content -->
            {% include "./inc/article_side.html" %}
            <!-- / side content -->
            <section>
                <section class="vbox">
                    <section class="scrollable wrapper">

                        <!-- .breadcrumb -->
                        <ul class="breadcrumb">
                            <li><a href="/admin/article/index"><i class="fa fa-home"></i> 网站内容</a></li>
                            {% for nav in breadcrumb%} {% if cate_id == nav.id %}
                            <li class="active">{{nav.title}} <span class="badge bg-info">{{_total}}</span> {% if allow == 0 %}<span class="label btn-warning">（该分类不允许发布内容）</span>{%
                                endif %}</li>
                            {%else%}
                            <li><a href="/admin/article/index?cate_id={{nav.id}}"><i class="fa fa-list-ul"></i> {{nav.title}}</a></li>
                            {% endif %} {% endfor %} {%if article.id >0 %}
                            <li> <i class="fa fa-list-ul"></i> {{article.title}} </li>{% endif %}
                        </ul>
                        <!-- / .breadcrumb -->
                        {%if sort%}
                        <section class="panel panel-default m-b-xs clearfix">
                            <header class="panel-heading text-right bg-light clearfix">
                                <ul class="nav nav-tabs pull-left">
                                    {%for val in sort.types%}
                                    <li class="{%if controller.get('sortid')|length > 0%}{%if controller.get('sortid')==val.enable%}active{%endif%}{%else%}{%if sort.defaultshow == val.enable%}active{%endif%}{%endif%}">
                                        <a href="/admin/article/index?pid={{pid}}&cate_id={{cate_id}}&group_id={{group_id}}&sortid={{val.enable}}" > {{val.name}}</a>
                                    </li>
                                   {%endfor%}
                                </ul>
                                <ul class="nav nav-pills pull-right">
                                    <li>
                                        <a href="#" class="panel-toggle text-muted" id="sorttoggle"><i class="fa fa-caret-down text"></i><i class="fa fa-caret-up text-active"></i></a>
                                    </li>
                                </ul>
                            </header>
                            <div class="panel-body collapse" id="sortbody" style="padding: 0">
                                <div class="tab-content">
                                    <table class="table table-hover table-condensed m-b-none" style="margin-top: -1px">
                                        <tbody>
                                        {%for val in typevar%}
                                        {%if val.search > 1 and val.available==1%}
                                        <tr>
                                            <td style="width: 140px" class="text-right">
                                               {{val.option.title}}:
                                            </td>
                                            <td>
                                                {%if 0 == nsobj[val.option.identifier] or null == nsobj[val.option.identifier]%}
                                                <span style="margin-right: 10px">全部</span>
                                                {%else%}
                                                <a href="/admin/article/index?pid={{pid}}&cate_id={{cate_id}}&group_id={{group_id}}&sortid={{sortid}}&sortval={{0|sort_url(val.option.identifier,typevar,nsobj)}}" class="text-info" style="margin-right: 10px">全部</a>
                                                {%endif%}
                                                {%for v in val.rules %}
                                                {%if v.id|sort_act(nsobj[val.option.identifier])%}
                                                <span style="margin-right: 10px">{{v.name}}{{val.option.unit}}</span>
                                                {%else%}
                                                <a href="/admin/article/index?pid={{pid}}&cate_id={{cate_id}}&group_id={{group_id}}&sortid={{sortid}}&sortval={{v.id|sort_url(val.option.identifier,typevar,nsobj)}}" class="text-info" style="margin-right: 10px">{{v.name}}{{val.option.unit}}</a>
                                                {%endif%}
                                            {%endfor%}

                                                <!--子栏目-->
                                                {%for v in val.rules %}
                                                {%if v.id|sort_act(nsobj[val.option.identifier])%}
                                                {% if v.children%}
                                                <div class="subtsm">

                                                    {% for v_ in v.children %}
                                                    {%if v_.id|sort_act(nsobj[val.option.identifier])%}
                                                    <span style="margin-right: 10px">{{v_.name}}{{val.option.unit}}</span>
                                                    {%else%}
                                                    <a href="/admin/article/index?pid={{pid}}&cate_id={{cate_id}}&group_id={{group_id}}&sortid={{sortid}}&sortval={{v_.id|sort_url(val.option.identifier,typevar,nsobj)}}" class="text-info" style="margin-right: 10px">{{v_.name}}{{val.option.unit}}</a>
                                                    {%endif%}
                                                    {% endfor %}
                                                </div>
                                                {%endif%}
                                                {%endif%}
                                                {%endfor%}
                                                <!--子栏目-->
                                                {%for v in val.rules %}
                                                {%if v.id|sort_act(nsobj[val.option.identifier])%}
                                                {% if v.children%}

                                                {% for v_ in v.children %}
                                                {%if v_.id|sort_act(nsobj[val.option.identifier])%}
                                                {% if v_.children%}
                                                <div class="subtsm">
                                                    {% for v__ in v_.children %}

                                                    {%if v__.id|sort_act(nsobj[val.option.identifier])%}

                                                    <span style="margin-right: 10px">{{v__.name}}{{val.option.unit}}</span>
                                                    {%else%}
                                                    <a href="/admin/article/index?pid={{pid}}&cate_id={{cate_id}}&group_id={{group_id}}&sortid={{sortid}}&sortval={{v__.id|sort_url(val.option.identifier,typevar,nsobj)}}" class="text-info" style="margin-right: 10px">{{v__.name}}{{val.option.unit}}</a>

                                                    {%endif%}
                                                    {%endfor%}
                                                </div>
                                                {%endif%}
                                                {%endif%}
                                                {% endfor %}

                                                {%endif%}
                                                {%endif%}
                                                {%endfor%}
                                            </td>

                                        </tr>
                                        {%endif%}
                                        {%endfor%}

                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </section>
                        {%endif%}
                        <section class="panel panel-default">
                            <header class="panel-heading">
                                <!--<i data-title="" data-placement="bottom" data-toggle="tooltip" class="fa fa-info-sign text-muted" data-original-title="" title=""><i class="fa fa-question-circle"></i></i>-->

                                {% if breadcrumb|length == 0%} [ {% if position %} <a href="/admin/article/index" class="text-info">全部</a>{%else%}<strong>全部</strong>{%endif%}
                                {%for key ,val in config.setup.DOCUMENT_POSITION %} {%if position != key %}<a href="/admin/article/index?position={{key}}"
                                class="text-info">{{val}}</a>{%else%}<strong>{{val}}</strong>{% endif %}&nbsp; {% endfor
                                %}] {%endif%} {%if model|length > 1 %}[ 模型：{%if model_id ==null %}<strong>全部</strong>{%else%}
                                <a
                                href="/admin/article/index?pid={{pid}}&cate_id={{cate_id}}" class="text-info"> 全部 </a>{%endif%}&nbsp; {% for val in modellist%} {% if model_id != val.id %}<a href="/admin/article/index?model_id={{val.id}}&pid={{pid}}&cate_id={{cate_id}}"
                                    class="text-info">{{val.title}}</a>{% else %}<strong>{{val.title}}</strong>{% endif %}&nbsp;
                                    {% endfor %} ]{% endif %} {% if groups %}[ 分组：{%if group_id ==0 %}<strong style="margin-right: 5px">全部</strong> {%else%} <a href="/admin/article/index?pid={{pid}}&cate_id={{cate_id}}"  class="text-info" style="margin-right: 5px">全部</a> {%endif%} {%for key ,val in groups %} {% if group_id != key %}<a href="/admin/article/index?pid={{pid}}&cate_id={{cate_id}}&group_id={{key}}&sortid={{sortid}}"  class="text-info">{{val}}</a>{%
                                        else %}<strong>{{val}}</strong>{% endif %}&nbsp; {% endfor %} ]{% endif %}
                            </header>
                            <div class="row wrapper">

                                <div class="col-sm-9 m-b-xs">
                                    <div class="">
                                        <div class="btn-group">
                                            <button {%if model|length> 1 %} data-toggle="dropdown" {% endif %} class="btn btn-info btn-sm document_add
                                                dropdown-toggle {% if allow == 0 or controller.get('cate_id')==null%}disabled{% endif %}" {%if model|length
                                                == 1 %} url="/admin/article/add?model_id={{modellist[0].id}}&pid={{pid}}&cate_id={{cate_id}}&group_id={{group_id}}&sortid={{sortid}}"{%endif%}
                                                >添加内容 {%if model|length > 1 %}<span class="caret"></span>{% endif %}</button>
                                            {%if model|length > 1 %}
                                            <ul class="dropdown-menu">

                                                {% for val in modellist%}
                                                <li> <a href="/admin/article/add?model_id={{val.id}}&pid={{pid}}&cate_id={{cate_id}}&group_id={{group_id}}&sortid={{sortid}}"
                                                    class="text-info">添加{{val.title}}</a></li>
                                                {% endfor %}

                                                <!--<li class="divider"></li>-->
                                                <!--<li><a href="#">添加内容</a></li>-->
                                            </ul>
                                            {% endif %}
                                        </div>
                                        <div class="btn-group">
                                            <a class="btn btn-sm btn-info ajax-post" target-form="ids" href="/admin/article/setstatus?status=1" target-form="ids">
                            启用
                        </a>
                                            <a class="btn btn-sm btn-info ajax-post" href="/admin/article/setstatus?status=0" target-form="ids">
                            禁用
                        </a>
                                        </div>
                                        <div class="btn-group">
                                            <a class="btn btn-sm btn-info ajax-post" target-form="ids" href="/{{ctx.controller}}/move">
                                            移动
                                        </a>
                                            <a class="btn btn-sm btn-info ajax-post" target-form="ids" href="/{{ctx.controller}}/copy">
                                            复制
                                        </a>
                                            <a class="btn btn-sm btn-info ajax-post" target-form="ids" hide-data="true" href="/{{ctx.controller}}/paste">
                                            粘贴
                                                <input type="hidden" class="hide-data" name="cate_id" value="{{cate_id}}">
                                                <input type="hidden" class="hide-data" name="pid" value="{{pid}}">
                                                <input type="hidden" class="hide-data" name="sort_id" value="{{sortid}}">
                                        </a>
                                        </div>

                                        <a class="btn btn-sm btn-info ajax-post confirm" target-form="ids" href="/admin/article/setstatus?status=-1">
                                            删除
                                        </a>
                                        <a class="btn btn-sm btn-info todo" target-form="ids" href="#">
                                            排序
                                        </a>
                                    </div>
                                </div>
                                <div class="col-sm-3">
                                    <div class="input-group pull-right search-form">
                                        <input type="text" class="input-sm form-control" name="{{model.search_key|default('title', true)}}" placeholder="请输入关键字"
                                        value="{{controller.get('title')}}">
                                        <span class="input-group-btn">
                        <button class="btn btn-sm btn-default" type="button" id="search" url="/admin/article/index?pid={{pid}}{%if cate_id >0%}&cate_id={{cate_id}}{%endif%}">搜索</button>
                      </span>
                                    </div>
                                </div>
                            </div>
                            <div class="table-responsive">
                                <table class="table table-striped b-t b-light">
                                    <thead>
                                        <tr>
                                            <th style="width:20px;">
                                                <label class="checkbox m-n i-checks">
                                                    <input type="checkbox"><i></i></label>
                                            </th>
                                            {% for field in list_grids %}
                                            <th>{{field.title}}</th>
                                            {% endfor %}
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {% for data in list %}
                                        <tr>
                                            <td>
                                                <label class="checkbox m-n i-checks">
                                                    <input class="ids" type="checkbox" name="ids" value="{{data.id}}"><i></i></label>
                                            </td>
                                            {% for grid in list_grids %}
                                            <td>{{data|get_list_field(grid,ctx.controller)| safe}}</td>
                                            {% endfor %}
                                        </tr>
                                        {% else %}
                                        <tr>
                                            <td colspan="{{list_grids|length + 1}}">
                                                <div class="alert alert-warning alert-block">
                                                    <button data-dismiss="alert" class="close" type="button">×</button>
                                                    <p>This would display if the 'item' collection were empty</p>
                                                </div>
                                            </td>
                                        </tr>

                                        {% endfor %}


                                    </tbody>
                                </table>
                            </div>
                            <footer class="panel-footer">
                                <div class="row">
                                 <div class="col-md-3">
                                      <div class="btn-group">
                                            <a class="btn btn-sm btn-default todo" target-form="ids" href="#">
                                                微信图文
                                            </a>
                                            <a class="btn btn-sm btn-default todo" target-form="ids" href="#">
                                                高级图文
                                            </a>
                                            <a class="btn btn-sm btn-default todo" target-form="ids" href="#">
                                                推送
                                            </a>
                                        </div>
                                 </div>

                                    <div class="col-md-9 text-right text-center-xs">
                                        {{pagerData | safe}}
                                    </div>
                                </div>
                            </footer>
                        </section>
                    </section>
                </section>
            </section>
        </section>
    </section>

</section>


{% endblock %} {% block script %}
<script src="/static/admin/js/zTree/jquery.ztree.core-3.5.min.js" type="text/javascript"></script>
<script type="text/javascript">
    <!--
    var zTree;
    var demoIframe;

    var setting = {
        async: {
            enable: true,
            url: "/admin/article/getmenu",
        },
        view: {
            showLine: true,
            selectedMulti: false,
        },
        callback: {
            onAsyncSuccess: zTreeOnAsyncSuccess

        }
        };

    function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) {
       // console.log(treeNode)
        var treeObj = $.fn.zTree.getZTreeObj(treeId);
        treeObj.expandAll(true);
        var id= $("#"+treeId).attr("data-cate");
        console.log(id);
        curMenu = treeObj.getNodeByParam("id", id, null);
        console.log(treeId)
        treeObj.selectNode(curMenu);
    };
    function expandNode(e) {
        var zTree = $.fn.zTree.getZTreeObj("tree"),
                type = e.data.type,
                nodes = zTree.getSelectedNodes();
        if (type == "expandAll") {
            zTree.expandAll(true);
        } else if (type == "collapseAll") {
            zTree.expandAll(false);
        }
    }


    //-->
    $(function(){
        var t = $("#tree");
        t = $.fn.zTree.init(t, setting).expandAll(true);
        $("#expandAllBtn").bind("click", {type:"expandAll"}, expandNode);
        $("#collapseAllBtn").bind("click", {type:"collapseAll"}, expandNode);
        //搜索功能
        $("#search").click(function(){
            var url = $(this).attr('url');
            var query  = $('.search-form').find('input').serialize();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
            query = query.replace(/^&/g,'');
            if( url.indexOf('?')>0 ){
                url += '&' + query;
            }else{
                url += '?' + query;
            }
            window.location.href = url;
        });

        //回车自动提交
        $('.search-form').find('input').keyup(function(event){
            if(event.keyCode===13){
                $("#search").click();
            }
        });

        //只有一个模型时，点击新增
        $('.document_add').click(function(){
            var url = $(this).attr('url');
            if(url != undefined && url != ''){
                window.location.href = url;
            }
        });
        if(localStorage.getItem("sortoggle")==1){
            $("#sorttoggle").addClass("active");
            $("#sortbody").removeClass("collapse");
        }
        //分类菜单
        $("#sorttoggle").click(function () {
            if(!$(this).is(".active")){
                localStorage.setItem("sortoggle",1)
            }else {
                localStorage.removeItem("sortoggle");
            }
        })
    })

</script>
{% endblock %}}